package com.leyou.item.controller;

import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.vo.PageResult;
import com.leyou.item.dto.BrandDTO;
import com.leyou.item.service.BrandService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @GetMapping("page")
    public ResponseEntity<PageResult<BrandDTO>> queryBrandByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "rows",defaultValue = "5") Integer rows,
            @RequestParam(value = "sortBy",required = false) String sortBy,
            @RequestParam(value = "desc",required = false) Boolean desc,
            @RequestParam(value = "key",required = false) String key
    ){
        return ResponseEntity.ok(this.brandService.queryBrandByPage(page,rows,sortBy,desc,key));
    }
    @PostMapping
    public ResponseEntity<Void> saveBrand(BrandDTO brandDTO,@RequestParam("cids") List<Long> ids){
        brandService.saveBrand(brandDTO,ids);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
    @PutMapping
    public ResponseEntity<Void> editBrand(BrandDTO brandDTO,@RequestParam("cids") List<Long> ids){
        brandService.editBrand(brandDTO,ids);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
    @DeleteMapping
    public ResponseEntity<Void> deleteBrandById(@RequestParam("id") Long id){
        this.brandService.deleteBrandById(id);
        return ResponseEntity.status(HttpStatus.OK).build();
    }
    @GetMapping("of/category")
    public ResponseEntity<List<BrandDTO>> queryBrandByCategoryId(@RequestParam("id") Long id){
        return ResponseEntity.ok(this.brandService.queryBrandByCategoryId(id));
    }
   @GetMapping("hello")
    public ResponseEntity<List<BrandDTO>> queryBrandByBrandIds(@RequestParam("ids") List<Long> ids){
        return ResponseEntity.ok(this.brandService.queryBrandByBrandIds(ids));
   }
 }
